<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <script th:src="@{/layui.js}" charset="utf-8"></script>
    <link rel="stylesheet"  th:href="@{/css/layui.css}" media="all">
</head>
<body>
<br><br>
<form class="layui-form" action="" id="form1">
<div class="layui-form-item">
    <div class="layui-inline">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-inline">
            <input type="hidden" name="id" th:value="${permission.id}">
            <input type="text" name="name"  autocomplete="off" class="layui-input" th:value="${permission.name}">
        </div>
    </div>
</div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">父功能节点</label>
            <div class="layui-input-inline">
                <select name="parent_id" id="parent_id" lay-search="" >
                    <option value="">直接选择</option>
                    <option value="0">根节点</option>
                    <option th:each="menu : ${parentMenus}"
                            th:value="${menu.id}"
                            th:text="${menu.name}"></option>
                </select>
            </div>
        </div>
    </div>
<div class="layui-form-item">
    <div class="layui-inline">
        <label class="layui-form-label">访问路径</label>
        <div class="layui-input-inline">
            <input type="text" name="path"  autocomplete="off" class="layui-input" th:value="${permission.path!=null}?${permission.path}"
            placeholder="/xx/xx/.....">
        </div>
    </div>

</div>

<div class="layui-form-item">
    <div class="layui-inline">
        <label class="layui-form-label">权限标识</label>
        <div class="layui-input-inline">
            <input type="text" autocomplete="off" class="layui-input" style="width: 300px" th:value="'内容:'+${permission.authorization_flag}">
            <select name="authorization_flag"  id="authorization_flag" lay-search="">
                <option value="" th:selected="${#strings.isEmpty(permission.authorization_flag)}">请重新选择</option>
                <option value="READ" th:selected="${permission.authorization_flag!=null}?${#strings.startsWith(permission.authorization_flag,'READ')}">READ</option>
                <option value="ADD" th:selected="${permission.authorization_flag!=null}?${#strings.startsWith(permission.authorization_flag,'ADD')}">ADD</option>
                <option value="EDIT" th:selected="${permission.authorization_flag!=null}?${#strings.startsWith(permission.authorization_flag,'EDIT')}">EDIT</option>
                <option value="SAVE" th:selected="${permission.authorization_flag!=null}?${#strings.startsWith(permission.authorization_flag,'SAVE')}">SAVE</option>
                <option value="DELETE" th:selected="${permission.authorization_flag!=null}?${#strings.startsWith(permission.authorization_flag,'DELETE')}">DELETE</option>
            </select>
        </div>
    </div>
</div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">是否生成菜单</label>
            <div class="layui-input-inline">
                <select name="is_menu"  lay-search="" >
                    <option th:selected="${permission.is_menu}=='1'" value="1">是</option>
                    <option th:selected="${permission.is_menu}=='0'" value="0">否</option>
                </select>
            </div>
        </div>
    </div>

<div class="layui-form-item">
    <div class="layui-input-block">
        <button type="button" onclick="doSave();" class="layui-btn" lay-submit="" lay-filter="demo1">保存</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
</div>
</form>


<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    var $,layer;
    layui.use(['form','laydate'], function(){
        var laydate = layui.laydate;
        $ = layui.jquery;
        layer = layui.layer;
        //日期
        laydate.render({
            elem: '#order_date'
        });

        //设置select的默认课程选中
        var parent_id = [[${permission.parent_id}]];//取到当前父节点
        var select = 'dd[lay-value=' + parent_id + ']';//属性选择器
        $('#parent_id').siblings("div.layui-form-select").find('dl').find(select).click();


    })
    
    
    function doSave() {
        var requestData = $("#form1").serialize();

        $.post("/permission/update",requestData,function (responseData) {
            console.log(responseData);
            if(responseData.success == 1){
                layer.alert("编辑成功",{yes:function () {
                    parent.layer.closeAll();
                }});
            }else{
                layer.alert("编辑失败",{yes:function () {
                    parent.layer.closeAll();
                    window.parent.location.reload();//修改成功后刷新父界面
                }});
            }
        });
    }
</script>


</body>
</html>